Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

289
Visualizações
Is there a way in cypress to accomodate cy.get(`[data-cy="${test}"]`).filter(':visible') and cy.get(`[data-cy="${test}"]`) in a single code?

I have a code like

cy.get(`[data-cy="${test}"]`).filter(':visible').click({force: true})

it works for some tests but for some elements there is no "filter" and those works without .filter(':visible'), so i am trying to accomodate both function in a single code to keep it generic for all kinds of buttons. Is there a way to do it?

I have tried few steps like:

cy.get(`[data-cy="${test}"]`).filter(':visible'|| ':hidden').click({force: true})

not sure whether it is right or wrong but its definielt not working!!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you are using {force: true} then it doesn't matter if the element is visible or hidden, cypress will click it. So in my opinion you don't need the filter option.

cy.get(`[data-cy="${test}"]`).click({force: true})

Or, If you want to directly apply the OR condition in .filter you can do:

cy.get(`[data-cy="${test}"]`).filter(':visible,:hidden').click({force: true})

Or, If you want to use If-Else you can do something like this:

cy.get(`[data-cy="${test}"]`).then(($ele) => {
  if ($ele.filter(':visible')) {
    cy.wrap($ele).click()
  } else if ($ele.filter(':hidden')) {
    cy.wrap($ele).click({force: true})
  }
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda